package com.bcx.crm.java.collection;

import java.util.AbstractList;
import java.util.List;

/**
 * Created by ys on 2018/1/21.
 */
public class ArrayToList {
    public static void main(String [] strings){
        List<String> list = ArrayToList.getList("sfs1", "sfs2", "sfs3", "sfs4", "sfs5");
        System.out.println(list.get(0));
        System.out.println(list.get(1));
        System.out.println(list.get(2));
        System.out.println(list.get(4));
    }
    public static List<String> getList(String s1, String s2,String... strings){
        return new AbstractList<String>() {
            @Override
            public int size() {
                return strings==null?2:strings.length+2;
            }

            @Override
            public String get(int index) {
                switch (index){
                    case 0:
                        return s1;
                    case 1:
                        return s2;
                    default:
                        return strings[index-2];
                }
            }
        };
    }
}
